﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoccerSimulator5000
{
    public class Schedule
    {
        public int numberOfWeeks = 48;
        int numberOfTeams;
        int numberOfGameWeeks;
        int numberOfFreeWeeks;

        int lengthOfGamePeriods;
        int extraGameWeeks;
        int lengthOfBreaks;
        int extraFreeWeeks;

        public List<int> gameWeeks = new List<int>();
        List<int> restWeeks = new List<int>();

        public Schedule()
        {
            
            
        }
        public void generateSchedule()
        {
            numberOfTeams = Game.teamList.Count();
            numberOfGameWeeks = (numberOfTeams - 1) * 2;

            numberOfFreeWeeks = numberOfWeeks - numberOfGameWeeks;

            lengthOfBreaks = numberOfFreeWeeks / 4;
            extraFreeWeeks = numberOfFreeWeeks % 4;

            lengthOfGamePeriods = numberOfGameWeeks / 4;
            extraGameWeeks = numberOfGameWeeks % 4;

            int firstBreakEnd = lengthOfBreaks;
            int firstGamePeriodEnd = firstBreakEnd + lengthOfGamePeriods + (extraGameWeeks/2);
            int secondBreakEnd = firstGamePeriodEnd + (extraFreeWeeks/2);
            int secondGamePeriodEnd = secondBreakEnd + (lengthOfGamePeriods);
            int thirdBreakEnd = secondGamePeriodEnd + (2 * lengthOfBreaks);
            int thirdGamePeriodEnd = thirdBreakEnd + (lengthOfGamePeriods) + (extraGameWeeks/2);
            int fourthBreakEnd = thirdGamePeriodEnd + (extraFreeWeeks/2);
            int fourthGamePeriodEnd = fourthBreakEnd + lengthOfGamePeriods;
            int fifthBreakEnd = fourthGamePeriodEnd + lengthOfBreaks;



            for (int i = 1; i <= numberOfWeeks; i++)
            {
                if (i <= firstBreakEnd)
                    restWeeks.Add(i);
                else if (i > firstBreakEnd && i <= firstGamePeriodEnd)
                    gameWeeks.Add(i);
                else if (i > firstGamePeriodEnd && i <= secondBreakEnd)
                    restWeeks.Add(i);
                else if (i > secondBreakEnd && i <= secondGamePeriodEnd)
                    gameWeeks.Add(i);
                else if (i > secondGamePeriodEnd && i <= thirdBreakEnd)
                    restWeeks.Add(i);
                else if (i > thirdBreakEnd && i <= thirdGamePeriodEnd)
                    gameWeeks.Add(i);
                else if (i > thirdGamePeriodEnd && i <= fourthBreakEnd)
                    restWeeks.Add(i);
                else if (i > fourthBreakEnd && i <= fourthGamePeriodEnd)
                    gameWeeks.Add(i);
                else if (i > fourthGamePeriodEnd && i <= fifthBreakEnd)
                    restWeeks.Add(i);
            }
        }
    }
}
